const { userLists } = require('../module/schema/userInfo')

const express = require('express')
const userRouter = express.Router()


userRouter.post('/register', async(req, res) => {
    let { userName, password, idNumber } = req.body
    let searchStatus = await userLists.findOne({ userName }) && userLists.findOne({ idNumber })

    if (searchStatus) {
        res.send({ code: 1, errInfo: '用户名已经注册' })
    } else {
        let insertStatus = await userLists.create(req.body)
        req.session.userInfo = { userName: insertStatus.userName, avatar: insertStatus.avatar, idNumber: insertStatus.idNumber }
        req.session.registerStatus = 1
        res.send({ code: 0, msg: '注册成功' })
    }
})

userRouter.get('/', async(req, res) => {
    res.send('请求成功')
})

module.exports = userRouter